<template>
	<div class="">
		<header class="top_bar">
			<a onclick="window.history.go(-1)" class="icon_back"></a>
			<h3 class="cartname">提现账号信息：</h3>
		</header>

		<!--<div class="line_height40 background_fff padding_top45 padding_lf10_rg10 border_bot_dcdcdc">
			<span>用户账号：</span>
			<span>15122931575</span>
		</div>
		<div class="line_height40 background_fff padding_lf10_rg10 border_bot_dcdcdc">
			<span>手机号：</span>
			<input type="text" placeholder="银行预留手机号" />
		</div>-->
		<div class="line_height40 background_fff padding_lf10_rg10 border_bot_dcdcdc padding_top45">
			<span>微信用户名：</span>
			<input v-model="Cardholder" type="text" placeholder="真实姓名，设置成功无法修改" style="width: 70%;"/>
		</div>
		<div class="line_height40 background_fff padding_lf10_rg10 border_bot_dcdcdc margin_bot10">
			<span>微信账号：</span>
			<input v-model="BankName" type="text" placeholder="请输入开户银行的名称" style="width: 70%;"/>
		</div>
		<div class="line_height40 background_fff padding_lf10_rg10 border_bot_dcdcdc">
			<span>支付宝用户名：</span>
			<input v-model="OpeningBank" type="text" placeholder="请输入开户银行的详细地址" style="width: 70%;"/>
		</div>
		<!--<div class="line_height40 background_fff padding_lf10_rg10 border_bot_dcdcdc">
			<span>身份证号：</span>
			<input type="text" placeholder="身份证号" />
		</div>-->
		<div class="line_height40 background_fff padding_lf10_rg10 border_bot_dcdcdc">
			<span>支付宝账号：</span>
			<input v-model="BankCard" type="text" placeholder="银行卡号" style="width: 70%;"/>
		</div>
		<div v-if="isShow==true" @click="PostBankInfo()" class="btn_bot">
			添加
		</div>
		<div v-else @click="PutBankInfo()" class="btn_bot">
			修改
		</div>
	</div>
</template>
<script>
	import { Toast } from 'mint-ui';
	export default {
		data() {
			return {
				Cardholder: '',
				BankCard: '',
				BankName: '',
				OpeningBank: '',
				bankInfo: [],
				isShow: false,
			}
		},
		mounted() {
			let _this = this
			_this.GetBankInfo()
		},
		methods: {
			GetBankInfo: function() {
				let _this = this
				_this.$http.get('/client/Banks', null, localStorage.Authorization, res => {
					if(res.code === 200) {
						console.log('银行卡信息res', res)
						_this.bankInfo = res.data.list
						if(res.data.dataCount>0) {
							_this.isShow = false
						}else {
							_this.isShow = true
						}
						if(_this.bankInfo.length>0) {
							_this.Cardholder = _this.bankInfo[0].Cardholder
							_this.BankCard = _this.bankInfo[0].BankCard
							_this.BankName = _this.bankInfo[0].BankName
							_this.OpeningBank = _this.bankInfo[0].OpeningBank
							
						}
					}
				})
			},
			PostBankInfo: function() {
				let _this = this
				_this.$http.post('/client/Banks', {
					Cardholder: _this.Cardholder,
					BankCard: _this.BankCard,
					BankName: _this.BankName,
					OpeningBank: _this.OpeningBank
				}, localStorage.Authorization, res => {
					if(res.code === 200) {
						console.log('添加银行卡信息res', res)
						Toast(res.data)
					}
				})
			},
			PutBankInfo: function() {
				let _this = this
				_this.$http.put('/client/Banks/'+_this.bankInfo[0].Id, {
					Cardholder: _this.Cardholder,
					BankCard: _this.BankCard,
					BankName: _this.BankName,
					OpeningBank: _this.OpeningBank
				}, localStorage.Authorization, res => {
					if(res.code === 200) {
						console.log('修改银行卡信息res', res)
						Toast(res.data)
					}
				})
			},
		}
	}
</script>
<style>
	@import '../assets/css/reg.css';
</style>